package com.sskj.mine.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.bean.GoogleCode;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.VerifyGoogleActivity;


public class VerifyGoogleActivityPresenter extends BasePresenter<VerifyGoogleActivity> {
    public void submit(boolean openCLose, String google_code, String google_secret) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.BIND_GOOGLE_CODE)
                .params("google_code", google_code)
                .params("google_secret", google_secret)
                .execute(new JsonCallBack<HttpData<Object>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
//                        toggleGoogleVerify(openCLose, google_code);
                        mView.onBindSuccess();
                    }
                });
    }



    public void requestData() {
        OkGo.<HttpData<GoogleCode>>post(HttpConfig.BASE_URL + HttpConfig.CREATE_GOOGLE_SECRET)
                .execute(new JsonCallBack<HttpData<GoogleCode>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<GoogleCode>> response) {
                        mView.onGoogleCodeSuccess(response.body().getData());
                    }

                });
    }


    // 开启谷歌认证
    public void toggleGoogleVerify(boolean isOpen, String google_code) {
        httpService.toggleGoogle(isOpen ? "start" : "stop", google_code)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        mView.onBindSuccess();

                    }
                });
    }
}
